package javaseof10day.day5.am;

import java.util.ArrayList;
import java.util.List;

public class UserAction {

	private  List<Users> userList =new ArrayList<Users>();

	public  Users add(Users users) {

		if (users != null) {

			Users u = new Users(users.getId(), users.getName(), users.getPassword());

			this.userList.add(u);
		}

		return users;
	}

	public boolean delete(int id) {

		List<Users> list = this.userList;

		for (Users users : list) {

			if (users.getId() == id) {

				list.remove(id);

				this.userList = list;
				
				return true;
			}

		}

		return false;
	}

	public Users selectOne(int id) {

		List<Users> list = this.userList;

		for (Users users : list) {

			if (users.getId() == id) {

				return users;
			}

		}
		return null;

	}

	

	public List<Users> selectAll() {



	
		return  this.userList;

	}
	
	
	public Users update(Users users) {

		List<Users> list = this.userList;

		for (Users u : list) {

			if (u.getId() == users.getId()) {
				u.setName(users.getName());
				u.setPassword(users.getPassword());
				list.add(u.getId(), u);

			}

		}
		return users;
	}

}
